import request from '@/utils/request'

// 查询图片列表
export function listPhoto(query) {
  return request({
    url: '/getAllPhotos',
    method: 'get'
  })
}

// 查询图片详细信息
export function getPhoto(id) {
  return request({
    url: '/getPhoto/' + id,
    method: 'get'
  })
}

// 新增图片
export function addPhoto(data) {
  return request({
    url: '/insertPhoto',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 修改图片
export function updatePhoto(data) {
  return request({
    url: '/updatePhoto',
    method: 'post',
    data: data
  })
}

// 删除图片
export function deletePhoto(id) {
  return request({
    url: '/deletePhoto/' + id,
    method: 'get'
  })
}

// 批量删除图片
export function batchDeletePhoto(ids) {
  const idArray = ids.split(',');
  const promises = idArray.map(id => deletePhoto(id));
  
  return Promise.all(promises).then(() => {
    return {
      code: 200,
      message: 'success',
      data: null
    }
  });
}

// 导出图片数据
export function exportPhoto(query) {
  return request({
    url: '/exportPhotos',
    method: 'get',
    params: query,
    responseType: 'blob'
  })
}

// 获取车辆的图片列表
export function getCarPhotos(carId) {
  return request({
    url: '/getCarPhotos/' + carId,
    method: 'get'
  })
}

// 设置主图
export function setMainPhoto(photoId) {
  return request({
    url: '/setMainPhoto/' + photoId,
    method: 'post'
  })
}

// 上传图片
export function uploadPhoto(carId, formData) {
  return request({
    url: '/uploadPhoto/' + carId,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取图片预览URL
export function getPhotoUrl(photoId) {
  return request({
    url: '/getPhotoUrl/' + photoId,
    method: 'get'
  })
} 